home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / diskproc / catchSignals.c next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  6.5 KB  |  233 lines

  1. /*
  2.  *   $RCSfile: catchSignals.c,v $  
  3.  *   $Revision: 1.2 $  
  4.  *   $Date: 1996/05/04 23:51:46 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37. #include "sysdefs.h"
  38. #include "queue_consist.h"
  39. #include "ess.h"
  40. #include "checking.h"
  41. #include "list.h"
  42. #include "error.h"
  43. #include "tid.h"
  44. #include "pool.h"
  45. #include "io.h"
  46. #include "bitvec.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "disk.h"
  51. #include "thread.h"
  52. #include "semaphore.h"
  53. #include "latch.h"
  54. #include "bf.h"
  55. #include "link.h"
  56. #include "volume.h"
  57. #include "trace.h"
  58. #include "msgvector.h"
  59.  
  60. #include "disk_funcs.h"
  61. #include "queues.h"
  62. #include "diskproc_globals.h"
  63. #include "diskproc_intfuncs.h"
  64. #include "diskproc_extfuncs.h"
  65.  
  66. #ifdef linux
  67. #include <bsd/signal.h>
  68. #endif
  69.  
  70. static void unexpected(int,int);
  71. static void quiet(int,int);
  72.  
  73. /* whatever is not included here, doesn't get touched. */
  74. struct siginfo {
  75.     int     sig;
  76.     char *string;
  77.     int     error_type;
  78.     void (*sv_handler)(int,int);
  79. } siginfo[] = {
  80.     { 0,        "<none>",     TYPE_FATAL,     unexpected },
  81.     { SIGHUP,    "SIGHUP",     TYPE_FATAL,     unexpected },
  82.     { SIGINT,    "SIGINT",     TYPE_QUIET,      quiet }, /* ^C */
  83.     { SIGQUIT,    "SIGQUIT",    TYPE_FATAL,  unexpected },
  84.     { SIGILL,    "SIGILL",    TYPE_FATAL,  unexpected },
  85.     { SIGTRAP,    "SIGTRAP",    TYPE_FATAL,  unexpected },
  86.     { SIGIOT,    "SIGIOT",    TYPE_FATAL,  unexpected },
  87. #ifndef linux
  88.     { SIGEMT,    "SIGEMT",    TYPE_FATAL,  unexpected },
  89. #endif linux
  90.     { SIGFPE,    "SIGFPE",    TYPE_FATAL,  unexpected },
  91.     { SIGKILL,    "SIGKILL",    0,          (void (*)(int,int))SIG_DFL },
  92.     { SIGBUS,    "SIGBUS",    TYPE_FATAL,  unexpected },
  93.     { SIGSEGV,    "SIGSEGV",    TYPE_FATAL,  unexpected }, /* abort() */
  94. #ifndef linux
  95.     { SIGSYS,    "SIGSYS",    TYPE_FATAL,  unexpected } ,
  96. #endif linux
  97.     { SIGPIPE,    "SIGPIPE",    TYPE_QUIET,      quiet }, /* serv exited */
  98.     { SIGALRM,    "SIGALRM",    0,               (void (*)(int,int))SIG_DFL },
  99.     { SIGTERM,    "SIGTERM",    0,          (void (*)(int,int))SIG_DFL },
  100.     { SIGURG,    "SIGURG",    TYPE_FATAL,  unexpected },
  101.     { SIGSTOP,    "SIGSTOP",    0,          (void (*)(int,int))SIG_DFL },
  102.     { SIGTSTP,    "SIGTSTP",    0,          (void (*)(int,int))SIG_DFL },
  103.     { SIGCONT,    "SIGCONT",    0,          (void (*)(int,int))SIG_DFL },
  104.     { SIGCHLD,    "SIGCHLD",    TYPE_FATAL,  unexpected },
  105.     { SIGTTIN,    "SIGTTIN",    0,          (void (*)(int,int))SIG_IGN },
  106.     { SIGTTOU,    "SIGTTOU",    0,          (void (*)(int,int))SIG_IGN },
  107.     { SIGIO,    "SIGIO",    TYPE_FATAL,  unexpected },
  108. #ifdef hpux
  109.     { SIGPWR,   "SIGPWR",   TYPE_FATAL,  unexpected },
  110.     /* this signal cannot be caught in HP-UX */
  111.  
  112.     /*{ _SIGRESERVE,    "SIGRESERVE",   TYPE_FATAL,  unexpected },*/
  113. #else
  114.     { SIGXCPU,  "SIGXCPU",  TYPE_FATAL,  unexpected },
  115.     { SIGXFSZ,  "SIGXFSZ",  TYPE_FATAL,  unexpected },
  116. #endif hpux
  117.     { SIGVTALRM,"SIGVTALRM",TYPE_FATAL,  unexpected },
  118.     { SIGPROF,    "SIGPROF",    0,          (void (*)(int,int))SIG_DFL },
  119.     { SIGWINCH,    "SIGWINCH",    0,          (void (*)(int,int))SIG_DFL },
  120. #ifndef linux
  121.     { SIGLOST,    "SIGLOST",    TYPE_FATAL,  unexpected },
  122. #endif linux
  123.     { SIGUSR1,    "SIGUSR1",    TYPE_FATAL,  unexpected },
  124.     { SIGUSR2,    "SIGUSR2",    TYPE_FATAL,  unexpected },
  125.     { 0, 0, 0}
  126. };
  127.  
  128. static void
  129. quiet(
  130.     int sig,
  131.     int code
  132. )
  133. {
  134.     TRPRINT(TR_DISKRW, TR_LEVEL_1, ("sig %d, code %d", sig, code));
  135.  
  136.     SM_ERROR(siginfo[sig].error_type, esmUNIXSIGNAL);
  137. }
  138.  
  139. static void 
  140. unexpected(
  141.     int sig,
  142.     int code
  143. )
  144. {
  145.     fprintf(stderr, "DISKRW %s: signal %6s signal code %d\n", 
  146. #            ifdef DEBUG
  147.             DiskName,
  148. #            else DEBUG
  149.             "",
  150. #            endif DEBUG
  151.             siginfo[sig].string, code);
  152.     SM_ERROR(siginfo[sig].error_type, esmUNIXSIGNAL);
  153. }
  154.  
  155.  
  156.  
  157. void
  158. catchSignals()
  159. {
  160.     extern int errno;
  161.     struct sigvec sv;
  162.     register int i, s;
  163.  
  164.     TRACE(TR_DISKRW, TR_LEVEL_1);
  165.  
  166.     sv.sv_mask = 0; /* or-ed in with mask for current signal */
  167.     sv.sv_flags = 0; /* don't use sigstack */
  168.     
  169.     for(i=1; i<NSIG && siginfo[i].sig != 0; i++) {
  170.         TRACE(TR_DISKRW, TR_LEVEL_1);
  171.         /* 
  172.          * Cast to no-arg func so it compiles. Maybes someday someone
  173.          * will fix signal.h to declare sv_handler properly.
  174.          */
  175. #if defined(DOTDOTDOT) || defined(hpux)
  176.         /* Sun C++ defines  DOTDOTDOT */
  177.         if((sv.sv_handler = (void (*)(...))siginfo[i].sv_handler)
  178.             == (void (*)(...))SIG_DFL)
  179. #elif defined(linux)
  180.         if((sv.sv_handler = (__sighandler_t)siginfo[i].sv_handler)
  181.             == SIG_DFL)
  182. #else
  183.         if((sv.sv_handler = (void (*)())siginfo[i].sv_handler)
  184.             == (void (*)())SIG_DFL)
  185. #endif
  186.             continue; /* don't bother */
  187.         s = siginfo[i].sig;
  188.         if (s == 0) {
  189.             break;  /* end of signal list */
  190.         }
  191. #ifdef hpux
  192.         if(sigvector(s, &sv, 0 /* don't care about old vector */) < 0) {
  193. #else
  194.         if(sigvec(s, &sv, 0 /* don't care about old vector */) < 0) {
  195. #endif hpux
  196.             TRPRINT(TR_DISKRW, TR_LEVEL_1, ("sigvec failure on sig %d",i));
  197.             SM_ERROR(TYPE_FATAL, errno);
  198.         } 
  199.     }
  200.     TRACE(TR_DISKRW, TR_LEVEL_1);
  201. }
  202.  
  203. void
  204. unCatchAbortSignal(
  205.     int sig
  206. )
  207. {
  208.  
  209. #ifdef notdef
  210.  
  211.     struct sigvec sv;
  212.  
  213.     TRPRINT(TR_DISKRW, TR_LEVEL_1, ("sig %d", sig));
  214.     sv.sv_mask = 0; /* or-ed in with mask for current signal */
  215.     sv.sv_flags = 0; /* don't use sigstack */
  216.     sv.sv_handler = (void (*)())SIG_DFL;
  217.  
  218.     if(sigvec(sig, &sv, 0 /* don't care about old vector */) < 0) {
  219.         perror("sigvec"); /* to avoid loops we don't call SM_ERROR */
  220.         onexit(errno);
  221.     }
  222. #else
  223.     /* This only gets called right before abort so we'd better
  224.      * change the *current* mask.
  225.      */
  226.     if(sigsetmask( ~(1<<(sig-1)) ) < 0) {
  227.           perror("sigsetmask");
  228.           onexit(errno);
  229.     }
  230. #endif
  231.  
  232. }
  233.